package cd.cdyb.sms.controller;

import cd.cdyb.sms.dto.PageResult;
import cd.cdyb.sms.dto.TemplateDto;
import cd.cdyb.sms.dto.expand.ExTemplateDto;
import cd.cdyb.sms.dto.query.QueryTemplateDto;
import cd.cdyb.sms.exception.BusinessException;
import cd.cdyb.sms.service.TemplateService;
import cd.cdyb.sms.utils.UserUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

/**
 * @Author: lilin
 * @CreateTime: 2024-05-14  16:03
 * @Description: 模板
 */
@RestController
@RequestMapping(value = "/template")
public class TemplateController {

    @Resource
    private TemplateService templateService;

    /**
     * 新增
     */
    @PostMapping("/insertTemplate")
    public void insertTemplate(@RequestBody @Valid TemplateDto templateDto) throws BusinessException {
        templateDto.setCompanyId(UserUtils.getCompanyId());
        templateService.insertSignature(templateDto);
    }

    /**
     * 客户端分页
     */
    @PostMapping("/findTemplatePageWithClient")
    public PageResult<ExTemplateDto> findTemplatePageWithClient(@RequestBody QueryTemplateDto queryTemplateDto) throws BusinessException {
        queryTemplateDto.setCompanyId(UserUtils.getCompanyId());
        return templateService.findTemplatePage(queryTemplateDto);
    }

    /**
     * 客户端分页
     */
    @PostMapping("/getTemplateById")
    public ExTemplateDto getTemplateById(@RequestBody ExTemplateDto exTemplateDto) throws BusinessException {
        return templateService.getTemplateById(exTemplateDto.getTemplateId());
    }

    /**
     * 管理端分页
     */
    @PostMapping("/findTemplatePageWithAdmin")
    public PageResult<ExTemplateDto> findTemplatePageWithAdmin(@RequestBody QueryTemplateDto queryTemplateDto) throws BusinessException {
        return templateService.findTemplatePage(queryTemplateDto);
    }

    /**
     * 首页模板统计-客户端
     **/
    @PostMapping("/indexTemplateStatisticsWithClient")
    public Map<String, Long> indexTemplateStatisticsWithClient() throws BusinessException {
        return templateService.indexTemplateStatisticsWithClient(UserUtils.getCompanyId());
    }

}
